# api
from common import host_port, read_yaml, Requestutil


class DeckTypeApi:

    # 新增
    def addDeckType(self, name):
        url = f'https://{host_port}/decklist/decktype/save'
        # 传入token
        header = {"token": read_yaml(key='token'), 'Content-Type': 'application/json'}
        payload = {"name": name}
        r = Requestutil.send_all_request(method='post', url=url, json=payload, headers=header, verify=False)
        return r.json()['code']

    # 查询
    def queryDeck(self, name):
        url = f'https://{host_port}/decklist/decktype/list'
        header = {'token': read_yaml(key='token')}
        payload = {'key': name}
        r = Requestutil.send_all_request(method='get', url=url, params=payload, headers=header, verify=False)
        code_ = r.json()['code']
        if code_ == 0:
            return r.json()['page']['list'][0]['name']
        return ''
